﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.UI.WebControls;
using JumbotCms.Common;
namespace JumbotCms.WebFile.Admin
{
    public partial class _forbidipedit : JumbotCms.API.AdminCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Admin_Load("0000", "html");
            id = Str2Str(q("id"));
            this.txtExpireDate.Attributes.Add("onFocus", "WdatePicker({isShowClear:false,readOnly:true,skin:'blue',startDate:'" + System.DateTime.Now.AddYears(1).ToShortDateString() + "'})");
            if (id == "0")
                this.txtExpireDate.Attributes.Add("value", System.DateTime.Now.AddYears(1).ToShortDateString());
            this.txtExpireDate.Attributes.Add("readonly", "readonly");
            Jumbot.DataOper.WebFormHandler wh = new Jumbot.DataOper.WebFormHandler(doh, "jcms_normal_forbidip", btnSave);
            wh.AddBind(txtStartIP, "StartIP2", true);
            wh.AddBind(txtEndIP, "EndIP2", true);
            wh.AddBind(txtExpireDate, "ExpireDate", true);
            if (id == "0")
            {
                wh.Mode = Jumbot.DataOper.OperationType.Add;
            }
            else
            {
                wh.ConditionExpress = "id=" + id;
                wh.Mode = Jumbot.DataOper.OperationType.Modify;
            }
            wh.validator = chkForm;
            wh.AddOk += new EventHandler(save_ok);
            wh.ModifyOk += new EventHandler(save_ok);
        }
        protected void bind_ok(object sender, EventArgs e)
        {
        }
        protected bool chkForm()
        {
            if (!CheckFormUrl())
                return false;
            if (!Page.IsValid)
                return false;
            return true;
        }
        /// <summary>
        /// 格式化为IP字符串
        /// </summary>
        /// <param name="ipDoubleStr"></param>
        /// <returns></returns>
        protected string GetIPStr(string ipDoubleStr)
        {
            long ipLong = long.Parse(ipDoubleStr);
            System.Net.IPAddress ip = Jumbot.Common.staticFunction.Long2IP(ipLong);
            return ip.ToString();
        }
        protected void save_ok(object sender, EventArgs e)
        {
            if (id == "0")
            {
                Jumbot.DataOper.DbOperEventArgs de = (Jumbot.DataOper.DbOperEventArgs)e;
                id = de.id.ToString();
            }
            doh.Reset();
            doh.ConditionExpress = "id=@id";
            doh.AddConditionParameter("@id", id);
            doh.AddFieldItem("StartIP", Jumbot.Common.staticFunction.IP2Long(System.Net.IPAddress.Parse(this.txtStartIP.Text)));
            doh.AddFieldItem("EndIP", Jumbot.Common.staticFunction.IP2Long(System.Net.IPAddress.Parse(this.txtEndIP.Text)));
            doh.AddFieldItem("Enabled", 1);
            doh.Update("jcms_normal_forbidip");
            FinalMessage("成功保存", site.Dir + "admin/close.htm", 0);
        }
    }
}
